package ru.jexp.rcp.supply.beans.ek;

import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.fieldassist.ControlDecoration;

import ru.jexp.rcp.supply.mui.JExpSupplyMessages;
import ru.jexp.utilities.StringUtil;

public class NotEmptyTextFieldValidation implements IValidator
{
	private final ControlDecoration decoration;

	public NotEmptyTextFieldValidation(ControlDecoration decoration)
	{
		this.decoration = decoration;
	}

	@Override
	public IStatus validate(Object value)
	{
		if (value instanceof String)
		{
			String newString = (String) value;
			if (StringUtil.isEmptyWithoutSpace(newString))
			{
				notValid();
				decoration.show();
				return ValidationStatus.error(JExpSupplyMessages.Global_text_field_validation_not_empty_msg);
			}
		}
		valid();
		decoration.hide();
		return ValidationStatus.ok();
	}

	protected void valid()
	{
	}

	protected void notValid()
	{
	}

}